<?php

namespace App\Http\Middleware;

use App\HuatiOwner;
use Closure;

class IsHuatiOwnerMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (!$request->has('token')) {
            return response()->json(error('没有token'));
        }
        //校验是不是圈主
        $user_id = hashid_decode($request->token);
        $huati_id = HuatiOwner::IsOwner($user_id);
        if (!$huati_id) {
            return response()->json(error('您不是圈主哦'));
        }
        return $next($request);
    }
}
